<%-- 
    Document   : StudentList
    Created on : Jun 3, 2013, 11:24:26 AM
    Author     : amaster
--%>


<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <table border ="1">
            <tr><th>Ma sv</th><th>Ten</th><th>Tuoi</th></tr>
        <%
            String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=testdb;user=sa;password=sa";
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection con = DriverManager.getConnection(connectionUrl);
            out.println("OK");
            
            String SQL = "SELECT * FROM Student";
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery(SQL);
            while (rs.next()) {
                out.println("<tr>");
                out.println("<td>" + rs.getString("masv") + "</td>");
                out.println("<td>" + rs.getString("ten") + "</td>");
                out.println("<td>" + rs.getInt("tuoi") + "</td>");
                out.println("</tr>");
            }

        %>
        
        </table>
        
    </body>
</html>
